// pages/user/myshop.js
//获取应用实例
const app = getApp()
var util = require('../../utils/util.js')
var http = require('../../utils/server.js')
Page({
  data: {
    list: [],
    id: null,
    showTip: true
  },

  onLoad: function(options) {
    var that = this;
    var notShowTip = wx.getStorageSync("not_show_shop_tip");
    if (notShowTip) {
      that.setData({
        showTip: false
      })
    }
    var currentUserInfo = wx.getStorageSync('userInfo');
    that.setData({
      id: currentUserInfo.shopId
    })

  },
  onShow: function() {
    var that = this;
    http.post({
      url: "Shop/getShopProduct",
      shop_id: that.data.id
    }, function(data) {
      console.log('小店商品', data)
      that.setData({
        list: data
      });
    })
  },

  onReachBottom: function() {
    console.info("onReachBottom")
  },
  remove: function(e) {
    console.info(e)
    var that = this;
    http.post({
      url: "Shop/delProduct",
      shop_product_id: e.currentTarget.dataset.id,
      shop_id: that.data.id
    }, function(data) {
      that.data.list.splice(e.currentTarget.dataset.index, 1);
      that.setData({
        list: that.data.list
      });
    });
  },
  close: function() {
    this.setData({
      showTip: false
    })
    wx.setStorage({
      key: 'not_show_shop_tip',
      data: true,
    });
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  toshare: function() {
    var that = this;
    wx.navigateTo({
      url: '/pages/user/shareShop?id=' + that.data.id + "&uid=" + wx.getStorageSync("token"),
    })
  },
  toaddproduct: function() {
    var that = this;
    wx.navigateTo({
      url: '/pages/user/addShopProduct?id=' + that.data.id,
    })
  }
})